 var app = getApp()
Page({
  /**
  * 页面的初始数据
  */
  data: {
      classfiySelect:"",
      doctorId:"",
      flag:"0",  //标志有没有进行搜索的输入
      fieldid:"",
      inputShowed:"",
      inputTyping:"",
      inputVal:"",
      rigId:'01',
      leftText: [{
        id: "01",
        office: "口腔内科",
      },
      {
        id: "02",
        office: "口腔外科",
      },
      {
        id: "03",
        office: "正畸科",
      },
      {
        id: "04",
        office: "修复科",
      },
      {
        id: "05",
        office: "儿童口腔科",
       },
      {
        id: "06",
        office: "牙粘膜病科",
      },],
      rightData: [{
        id: "01",
        title:"口腔内科",
        frist: [],
      },
      {
        id: "02",
        title:"口腔外科",
        frist: [
         
        ],
      },
      {
        id: "03",
        title:"正畸科",
        frist: [
          
        ],
      },
      {
        id: "04",
        title:"修复科",
        frist: [
      ],
      },
      {
        id: "05",
        title:"儿童口腔科",
      },
      {
        id: "06",
        title:"牙粘膜病科",
      },
    ],
  },
   
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function(options) {
    this.setData({
      classfiySelect: this.data.leftText[0].id,
    })
    console.log(this.data.classfiySelect)
    this.setData({
      doctorId:app.globalData.doctorId
    })
    this.showDoctor();
  },
  showDoctor:function()
  {
    var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientOrderView2', //在PatientOrderController类中
      method: 'GET',
      data: {
        unitphone:getApp().globalData.unitphone,
        flag:this.data.flag,
        searchText:this.data.inputVal
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        console.log(res.data)
        let fi={};
        let first=[];
        for(let j=0;j<6;j++)
        {
          for(let i=0;i<res.data.length;i++)
          {
            if(res.data[i].doctorFieldForm.doctorField==that.data.leftText[j].office)
            {
              var doctorId0="";
              var doctorRank0="";
              var doctorName0 ="";
              var photoUrl0="";
              doctorName0=res.data[i].doctorInfoForm.doctorName;
              doctorId0=res.data[i].doctorInfoForm.doctorId;
              doctorRank0=res.data[i].doctorInfoForm.doctorRank;
              photoUrl0=res.data[i].doctorPhoto;
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0};        
              first.push(fi);
            }
          }

            if(j==0)
          {
            that.setData({
              "rightData[0].frist":first
            })
          }
          else if(j==1)
          {
            that.setData({
              "rightData[1].frist":first
            })
          }
          else if(j==2)
          {
            that.setData({
              "rightData[2].frist":first
            })
          }
          else if(j==3)
          {
            that.setData({
              "rightData[3].frist":first
            })
          }
         else if(j==4)
         {
            that.setData({
              "rightData[4].frist":first
            })
         }
         else if(j==5)
         {
          that.setData({
            "rightData[5].frist":first
          })
         }
         else if(j==6)
         {
          that.setData({
            "rightData[6].frist":first
          })
         }
         first=[];
        }
      },
      fail:(res)=>{
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
      }
    })
  },
  showInput: function () {
    this.setData({
    inputShowed: true
    });
    },
    hideInput: function () {
    this.setData({
    inputVal: "",
    inputShowed: false
    });
    // getList(this);
    },
    clearInput: function () {
    this.setData({
    inputVal: "",
    flag:0,
    });
    this.showDoctor
    // getList(this);
    },
    inputTyping: function (e) {
    //搜索数据
    // getList(this, e.detail.value);
    this.setData({
    inputVal: e.detail.value,
    flag:1
    });
    if(e.detail.value.length==0)
    {
      this.setData({
        flag:0
        });
    }
    console.log(this.data.inputVal);
    this.showDoctor();
    },

  /**
  * 生命周期函数--监听页面初次渲染完成
  */
  onReady: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面隐藏
  */
  onHide: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面卸载
  */
  onUnload: function() {
   
  },
   
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function() {
   
  },
   
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function() {
   
  },
   
  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function() {
   
  },
  //滚动触发
  scroll: function(e) {
    var scrollTop = e.detail.scrollTop,
    h = 0,
    classfiySelect;
    var that = this;
    that.data.leftText.forEach(function(clssfiy, i) {
      var _h =26 + that.length(clssfiy['id'])*102;
      if (scrollTop >= h){
        classfiySelect = clssfiy['id'];
      }
    h +=_h;
    })
    that.setData({
    classfiySelect: classfiySelect,
    })
    console.log(that.data.classfiySelect)
  },
  //求每一栏高度
  length: function(e) {
    var that = this;
    var rightData = that.data.rightData;
    for (var i = 0; i < rightData.length; i++) {
      if(rightData[i]['id']==e){
        return rightData[i]['frist'].length;
      }
    }
  },
  
  
  
  //点击左边事件
  left_list: function(e) {
    var that = this;
    var l_id = e.currentTarget.dataset.id;
    that.setData({
      rigId: l_id,
    })
    console.log(that.data.rigId)
  },
  //跳转详情界面
  particulars:function(e){
    console.log(e)
    var chooseDoctor = e.currentTarget.dataset.index;
    console.log(chooseDoctor)
    app.globalData.doctorId=chooseDoctor
    console.log(app.globalData.doctorId)
    wx.navigateTo({
      url: '../days/days',
    })
    /*var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientOrderView2', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
          doctorId:app.globalData.doctorId
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        wx.navigateTo({
          url:'../days/days',
        })
      },
      fail(res){
       wx.navigateTo({
         url: '../days/days',
       })
      }
    })*/
  }
})